package com.asman.worker;

import android.app.Application;
import android.content.Context;

import com.asman.base.lib.BuildConfig;
import com.asman.oss.OSSUtils;
import com.asman.push.PushUtils;
import com.asman.umeng.DplusReactPackage;
import com.asman.umeng.RNUMConfigure;
import com.asman.worker.push.KeyConst;
import com.asman.worker.rn.MyNativePackage;
import com.asman.worker.rn_ui.MyNativeUIPackage;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.microsoft.codepush.react.CodePush;
import com.reactnativecommunity.art.ARTPackage;
import com.brentvatne.react.ReactVideoPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import com.umeng.commonsdk.UMConfigure;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

    public static Context context;

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
            return false;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            List<ReactPackage> packages = new PackageList(this).getPackages();
            packages.add(new MyNativePackage());//原生功能模块
            packages.add(new MyNativeUIPackage());//UI 原生能力
            packages.add(new CodePush("38XkNIbNtArqTNzhJK9dqdTTRamG4ksvOXqog", getApplicationContext(), false, "http://47.97.155.224:3000"));
            packages.add(new ARTPackage());
            packages.add(new ReactVideoPackage());
            packages.add(new DplusReactPackage());
            return packages;
        }

        @Override
        protected String getJSMainModuleName() {
            return "index";
        }

        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }

//        @Nullable
//        @Override
//        protected String getJSBundleFile() {
//            return UpdateContext.getBundleUrl(MainApplication.this);
//        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        SoLoader.init(this, false);
        RNUMConfigure.init(this, KeyConst.UMENG, "umeng", UMConfigure.DEVICE_TYPE_PHONE, "", false);
        //初始化推送+厂商通道
        PushUtils.INSTANCE.init(
                this,
                false,
                "1",
                "小牛师傅",
                "小牛师傅",
                KeyConst.MI_APP_ID,
                KeyConst.MI_APP_KEY,
                KeyConst.OPPO_APP_KEY,
                KeyConst.OPPO_APP_SECRET
        );
        OSSUtils.init(this, "", false);
    }
}
